<template>

<!--  表单-->
  <div id="add">
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px; margin-bottom: 10px">
      <el-breadcrumb-item :to="{ path: '/' }">
        <i class="el-icon-s-promotion"></i> 后台管理
      </el-breadcrumb-item>
      <el-breadcrumb-item>部门管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-divider></el-divider>
    <div class="bed-main">
      <div class="d-flex justify-content-end" style="padding: 10px;" align="right">
        <el-button type="primary" style="width: 100px;" @click="addBed">添加</el-button>
      </div>
  <el-table
      stripe
      border
      :data="tableData"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
      default-expand-all
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
    <el-table-column
        prop="department"
        label="部门"
        el-table:width="80">
    </el-table-column>
    <el-table-column
        type="success"
        prop="state"
        label="状态"
        width="100">
      <template slot-scope="scope">
        <div class="cell" v-if="scope.row.state == '0'">正常</div>
        <div class="cell" v-if="scope.row.state == '1'">停用</div>
      </template>
    </el-table-column>
    <el-table-column
        fixed="right"
        label="操作"
        label-width="180">

      <template slot-scope="scope">
        <el-button size="mini" type="primary" @click="handleModify(scope.$index, tableData)">编辑</el-button>
        <el-button size="mini" type="danger" @click="handleDelete(scope.$index, tableData)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>

<!--添加弹出框      -->

      <el-dialog
          title="修改部门"
          :visible.sync="dialogVisible"
          width="570px">

        <div class="content"  width="300px">
          <div class="d-flex align-items-center mb-15">
            <span class="w-100 text-left">父部门:
             <el-cascader :options="options">
            <template slot-scope="{ node, data }" placeholder="请选择">
              <span>{{ data.label }}</span>
              <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
            </template>
          </el-cascader>
            </span>
          </div>

          <div class="d-flex align-items-center mb-15">
            <span class="w-100 text-left">部门名称:
            <el-input
                style="width: 350px;"
                placeholder="请输入部门名称"
                v-model="form.name"
                clearable>
            </el-input>
            </span>
          </div>

          <div class="d-flex align-items-center mb-15">
            <span class="w-100 text-left">权限:
              <el-select v-model="form.permissions" placeholder="选择">
                <el-option label="管理员" value="gaunliyuan"></el-option>
                <el-option label="酒店管理员" value="joudianguanliyuan"></el-option>
                <el-option label="酒店员工" value="joudianyuangon"></el-option>
                <el-option label="防疫人员" value="fangyirenyuan"></el-option>
              </el-select>
            </span>
          </div>

          <div class="d-flex align-items-center mb-15">
            <space class="w-100 text-left">状态:
              <el-radio v-model="form.state" label="0">正常</el-radio>
              <el-radio v-model="form.state" label="1">停用</el-radio>
            </space>
          </div>

        </div>
        <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="confirm">确 定</el-button>
        </span>
      </el-dialog>
      </div>
  </div>
</template>


<script>
export default {

  methods: {
    /*添加部门*/
    addBed() {
      this.form={
        state: undefined,
      }
      this.dialogVisible = true
    },
    /*删除部门*/
    handleDelete(index, rows) {
      rows.splice(index, 1);
    },
    /*编辑部门信息*/
    handleModify(index,rows){
      rows.splice(index,rows)
      this.form=rows
      this.state=rows.state
      this.dialogVisible = true
    }

  },

  data() {
    return {
      labelPosition:'left',
      dialogVisible: false,
      form: {
        id: undefined,
        name: undefined,
        permissions: undefined,
        state: undefined,
      },
      tableData: [{
        id:'1',
        department: '管理员',
        state: '0',


      }, {
        id:'2',
        department: '普通管理员',
        state: '0',

      },{
        id:'3',
        department: '懒狗国际酒店',
        state: '0',
      },
        {
        id: 4,
        department: 'SixOneFour国际度假酒店',
        state: '0',
        children: [{
          id: 41,
          department: 'SixOneFour国际度假酒店-前台',
          state: '0',
        }]
      },{
        id:'5',
        department: '防疫人员',
        state: '0',
      },{
          id: 6,
          department: 'oneonetwo国际度假酒店',
          state: '0',
          children: [{
            id: 61,
            department: 'oneonetwo国际度假酒店-前台',
            state: '0',
          },{
            id: 62,
            department: 'oneonetwo国际度假酒店-维修部',
            state: '0',
          }],
        }],
      options: [{
        value: 'guanliyuan',
        label: '管理员',
      },
        {
          value: 'putongchengyuan',
          label: '普通成员',
        },

        {
          value: 'langouguojinjoudian',
          label: '懒狗国际酒店',
        },
        {
          value: 'SixOneFourguojindujiajoudian',
          label: 'SixOneFour国际度假酒店',
          children: [{
            value: 'qiantai',
            label: '前台'
          }]
        },{
          value: 'fangyirenyuan',
          label: '防疫人员',
        },]
    }
  }
}
</script>

<style   scoped>


</style>

